package com.star.warmwinter.module.user.ui;

import android.databinding.DataBindingUtil;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;

import com.star.tool.util.SizeUtils;
import com.star.warmwinter.R;
import com.star.warmwinter.common.BaseActivity;
import com.star.warmwinter.databinding.CommonLoginPwdBinding;
import com.star.warmwinter.module.user.viewCtrl.ForgetPwdCtrl;
import com.star.warmwinter.module.user.viewCtrl.LoginCtrl;
import com.star.warmwinter.module.user.viewCtrl.RegisterCtrl;

import static com.star.warmwinter.module.user.ui.CommonLoginTelActivity.FORGET_PWD_TEL;
import static com.star.warmwinter.module.user.ui.CommonLoginTelActivity.LOGIN_TYPE_FORGET_PWD;
import static com.star.warmwinter.module.user.ui.CommonLoginTelActivity.LOGIN_TYPE_KEY;
import static com.star.warmwinter.module.user.ui.CommonLoginTelActivity.LOGIN_TYPE_LOGIN;
import static com.star.warmwinter.module.user.ui.CommonLoginTelActivity.LOGIN_TYPE_REGISTER;

/**
 * Author: blackbai11
 * Date: 2018/5/31
 * Description: 通用手机密码登录逻辑页面(登录,注册,忘记密码)
 */
public class CommonLoginPwdActivity extends BaseActivity {

    private CommonLoginPwdBinding mBinding;

    @Override
    public void bindLayout() {
        setContentView(R.layout.common_login_pwd);
        mBinding = DataBindingUtil.setContentView(this, R.layout.common_login_pwd);
    }

    @Override
    public void doBusiness() {
        //设置密码图标大小
        Drawable drawable = getResources().getDrawable(R.mipmap.icon_pwd);
        drawable.setBounds(0, 0, SizeUtils.dp2px(20),SizeUtils.dp2px(11));
        mBinding.tvNoticePwd.setCompoundDrawables(drawable, null, null, null);

        int type = getIntent().getIntExtra(LOGIN_TYPE_KEY, -1);
        String forgetPwdTel = getIntent().getStringExtra(FORGET_PWD_TEL);
        switch (type) {
            case LOGIN_TYPE_REGISTER:
                mBinding.titleBar.setTitle("注册");
                mBinding.btnLogin.setText("完成注册");
                mBinding.setCommonLoginCtrl(new RegisterCtrl(this));
                break;

            case LOGIN_TYPE_LOGIN:
                mBinding.titleBar.setTitle("登录");
                mBinding.tvForgetPwd.setVisibility(View.VISIBLE);
                LoginCtrl loginCtrl = new LoginCtrl(this);
                loginCtrl.getCommonLoginVM().setPhone(forgetPwdTel);
                mBinding.setCommonLoginCtrl(loginCtrl);
                break;

            case LOGIN_TYPE_FORGET_PWD:
                mBinding.titleBar.setTitle("忘记密码");
                //设置第一行密码顶部间距
                ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mBinding.tvNoticePwd.getLayoutParams();
                lp.setMargins(lp.leftMargin, SizeUtils.dp2px(40), lp.rightMargin, lp.bottomMargin);
                mBinding.tvNoticePwd.setLayoutParams(lp);
                //设置确认密码输入框显示
                mBinding.tvNoticePwd2.setVisibility(View.VISIBLE);
                mBinding.edPwd2.setVisibility(View.VISIBLE);
                mBinding.view2.setVisibility(View.VISIBLE);
                mBinding.btnLogin.setText("确认");
                mBinding.setCommonLoginCtrl(new ForgetPwdCtrl(this));
                break;
        }
    }
}
